<?php if (!defined('THINK_PATH')) exit();?><html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>物业费缴费系统</title>
    <script type="text/javascript" src="//apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>

    <div style="margin-left:2%;">商品类型：</div><br/>
    <select id="product_type" type="" style="width:96%;height:35px;margin-left:2%;" required="required">
        <option value="测试">测试</option>
        <option value="物业费">物业费</option>
        <option value="购买水果">购买水果</option>
    </select><br /><br />
    <div style="margin-left:2%;">支付金额(元)：</div><br/>
    <input id="total_fee" type="text" style="width:96%;height:35px;margin-left:2%;" value="0.01" required="required" /><br /><br />
    <div style="margin-left:2%;">是否足额：</div><br/>
    <select id="is_enough" type="" style="width:96%;height:35px;margin-left:2%;" required="required">
        <option value="Y">是</option>
        <option value="N">否</option>
    </select>
    <br /><br />
    <div style="margin-left:2%;">授权码：</div><br/>
    <input id="auth_code" type="text" style="width:96%; height:35px; margin-left:2%;" required="required" /><br /><br />
    <div align="center">
        <input id="submit" type="button" value="提交刷卡" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer;  color:white;  font-size:16px;" onclick="pay()" />
    </div>
    <table>
        <tbody id="tip">
            <tr>
                <th>时间</th>
                <th>信息</th>
            </tr>
        </tbody>
    </table>

<script type="text/javascript">
    //微信支付
    function pay(){
        $('#tip').prepend('<tr><td>'+Date()+'</td><td>正在付款中，请等待……</td></tr>');
        var pay_url = "<?php echo U('Deal/micropay');?>";
        var query_url = "<?php echo U('Query/wxorder');?>";
        $.post(
            pay_url,
            {
                action: 'post',
                product_type: $('#product_type').val(),
                total_fee: $('#total_fee').val(),
                is_enough: $('#is_enough').val(),
                auth_code: $('#auth_code').val(),
            },
            function(data){
                if(data.state == undefined){
                    $('#tip').prepend('<tr><td>'+Date()+'</td><td>订单已关闭或订单已撤销，如有必要，请重新提交订单！</td></tr>');
                }else if(data.state != true){
                    $('#tip').prepend('<tr><td>'+Date()+'</td><td>'+data.err_code_des+'</td></tr>');
                }else{
                    $('#tip').prepend('<tr><td>'+Date()+'</td><td>订单支付成功！<a href="'+query_url+'/transaction_id/'+data.transaction_id+'">查询订单</a></td></tr>');
                }
            },
            "json"
        )
    }

    //微信支付订单查询并带数据跳转到指定页
    function query(condition, url){
        var k = condition['k'];
        var v = condition['v'];
        if(k == 'out_trade_no'){
            $.post(
                "<?php echo U('Query/wxorder');?>",
                {
                    action: 'post',
                    out_trade_no: v
                },
                function(data){
                    redirect(url, 'post', data);
                },
                'json'
            )
        }else if(k == 'transaction_id'){
            $.post(
                "<?php echo U('Query/wxorder');?>",
                {
                    action: 'post',
                    transaction_id: v
                },
                function(data){
                    redirect(url, 'post', data);
                },
                'json'
            )
        }
    }

    //带数据跳转
    function redirect(url, method, data){
        $.ajax({
            type: method,
            dataType: 'json',
            url: url,
            data: data,
            complete: function(){
                location.replace(url);
            }
        })
    }
</script>
</body>
</html>